package library;

import java.util.ArrayList;
import java.util.List;

public class User {
	  private String id;
	    private String name;
	    private String gender;
	    private String password;

	    public User(String id, String name, String gender, String password) {
	        this.id = id;
	        this.name = name;
	        this.gender = gender;
	        this.password = password;
	    }

	    // Getters and setters

	    public String getId() {
	        return id;
	    }

	    public String getName() {
	        return name;
	    }

	    public String getGender() {
	        return gender;
	    }

	    public String getPassword() {
	        return password;
	    }
	}

	class Administrator extends User {
	    public Administrator(String id, String name, String gender, String password) {
	        super(id, name, gender, password);
	    }
	}

	class Student extends User {
	    private List<Book> borrowedBooks;

	    public Student(String id, String name, String gender, String password) {
	        super(id, name, gender, password);
	        borrowedBooks = new ArrayList<>();
	    }

	    public void borrowBook(Book book) {
	        if (book.getQuantity() > 0) {
	            book.quantity--;
	            borrowedBooks.add(book);
	            System.out.println("借书成功\n借书期限为：2023-06-12至2023-08-11");
	        } else {
	            System.out.println("图书馆没有该书");
	        }
	    }

	    public void returnBook(int bookId) {
	        boolean returned = false;
	        for (int i = 0; i < borrowedBooks.size(); i++) {
	            Book book = borrowedBooks.get(i);
	            if (book.getId() == bookId) {
	                borrowedBooks.remove(i);
	                book.quantity++;
	                returned = true;
	                break;
	            }
	        }
	        if (returned) {
	            System.out.println("还书成功");
	        } else {
	            System.out.println("该书不是图书馆的");
	        }
	    }

		public void setPassword(String newPassword) {
			// TODO Auto-generated method stub
			
		}

		public void setName(String name) {
			// TODO Auto-generated method stub
			
		}

		public void setGender(String gender) {
			// TODO Auto-generated method stub
			
		}
}

